Description: This sample demonstrates how to use IOKitLib to find CD-ROM media mounted on the system. It also shows how to open, read raw sectors from, and close the drive.
printf( "IOMasterPort returned %d\n", kernResult );
/*! @function IOServiceMatching
@abstract Create a matching dictionary that specifies an IOService class match.
@discussion A very common matching criteria for IOService is based on its class. IOServiceMatching will create a matching dictionary that specifies any IOService of a class, or its subclasses. The class is specified by C-string name.
@param name The class name, as a const C-string. Class matching is successful on IOService's of this class or any subclass.
@result The matching dictionary created, is returned on success, or zero on failure. The dictionary is commonly passed to IOServiceGetMatchingServices or IOServiceAddNotification which will consume a reference, otherwise it should be released with CFRelease by the caller. */
// CD media are instances of class kIOCDMediaClass
// Each IOMedia object has a property with key kIOMediaEjectable which is true if the media
// is indeed ejectable. So add this property to the CFDictionary we're matching on.
}
/*! @function IOServiceGetMatchingServices
@abstract Look up registered IOService objects that match a matching dictionary.
@discussion This is the preferred method of finding IOService objects currently registered by IOKit. IOServiceAddNotification can also supply this information and install a notification of new IOServices. The matching information used in the matching dictionary may vary depending on the class of service being looked up.
@param masterPort The master port obtained from IOMasterPort().
@param matching A CF dictionary containing matching information, of which one reference is consumed by this function. IOKitLib can contruct matching dictionaries for common criteria with helper functions such as IOServiceMatching, IOOpenFirmwarePathMatching.
@param existing An iterator handle is returned on success, and should be released by the caller when the iteration is finished.
@abstract Returns the next object in an iteration.
@discussion This function returns the next object in an iteration, or zero if no more remain or the iterator is invalid.
@param iterator An IOKit iterator handle.
@result If the iterator handle is valid, the next element in the iteration is returned, otherwise zero is returned. */
nextMedia = IOIteratorNext( mediaIterator );
if ( nextMedia == NULL )
{
*bsdPath = '\0';
}
else {
CFTypeRef bsdPathAsCFString;
/*! @function IORegistryEntryCreateCFProperty
@abstract Create a CF representation of a registry entry's property.
@discussion This function creates an instantaneous snapshot of a registry entry property, creating a CF container analogue in the caller's task. Not every object available in the kernel is represented as a CF container; currently OSDictionary, OSArray, OSSet, OSSymbol, OSString, OSData, OSNumber, OSBoolean are created as their CF counterparts.
@param entry The registry entry handle whose property to copy.
@param key A CFString specifying the property name.
@param allocator The CF allocator to use when creating the CF container.
@param options No options are currently defined.
@result A CF container is created and returned the caller on success. The caller should release with CFRelease. */
@abstract Releases an object handle previously returned by IOKitLib.
@discussion All objects returned by IOKitLib should be released with this function when access to them is no longer needed. Using the object after it has been released may or may not return an error, depending on how many references the task has to the same object in the kernel.
@param object The IOKit object to release.
@result A kern_return_t error code. */
IOObjectRelease( nextMedia );
return kernResult;
}
// Given the path to a CD drive, open the drive.
// Return the file descriptor associated with the device.